﻿// Study0210.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 循环语句：while循环，do-while循环,for循环，其它控制语句

#include <iostream>;
using namespace std;

int main()
{
    //while循环
    //求自然数1~10之和
    cout << "===============================\n";
    int n{ 0 }, sum{ 0 };
    while (n<10)
    {
        n += 1;
        sum += n;      
    }
    cout << "自然数1~10之和为：" << sum << endl;

    //do-while循环
    //输入一个数，将各位数字翻转后输出
    cout << "===============================\n";
    cout << "输入一个四位数：" << endl;
    int m,right_digit;
    cin >> m;
    cout << "该四位数翻转后为：";
    do
    {
        right_digit = m % 10;
        cout << right_digit;
        m /= 10;
    } while (m!=0);
    cout << endl;

    //for循环
    //输入一个整数求出它的所有因子
    cout << "===============================\n";
    cout << "输入一个正整数：" << endl;
    int num;
    cin >> num;
    cout << "正整数" << num << "所有因子有：";
    for (int i = 1; i <= num; i++)
    {
        if (num%i==0)
        {
            cout << i<<",";
        }
    }
    cout << "\b."<<endl;

    //编程输出特定图案
    cout << "===============================\n";
    for (int i = 1; i <= 4; i++)
    {
        for (int j = 0; j < 18-2*i; j++)
        {
            cout << " ";
        }
        for (int j = 0; j < 2 * i-1; j++)
        {
            cout << "*";
        }
        cout << endl;
    }
    for (int i = 1; i <= 3; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cout << " ";
        }
        for (int j = 0; j < 7-2*i; j++)
        {
            cout << "*";
        }
        cout << endl;
    }
    cout << endl;
    //输入一系列整数，统计出正整数个数i和负整数个数j，输入0时结束
    cout << "===============================\n";
    cout << "请输入一个数：";
    int input, i{ 0 }, j{0};
    cin >> input;
    cout << endl;
    while (input!=0)
    {
        input > 0 ? i++ : j++;
        cout << "请输入一个数：";
        cin >> input;
        cout << endl;
    }
    cout << "正整数个数：" << i << "个，\n";
    cout << "负整数个数：" << j << "个。"<<endl;
    return 0;
}
